<template>
	<u-cell-group>
		<u-cell-item v-if="selectedFields.includes(26) || displayAll" required :arrow="false" title="老板名称" >
			<u-input inputAlign="right" v-model="form.BossName" placeholder="老板名称"></u-input>
		</u-cell-item>
		<u-cell-item v-if="selectedFields.includes(27) || displayAll" required :arrow="false" title="老板手机号" >
			<u-input inputAlign="right" v-model="form.BossPhone" placeholder="老板手机号"></u-input>
		</u-cell-item>
		<block v-if="selectedFields.includes(28) || displayAll">
			<u-cell-item  required :border-bottom="false" :arrow="false" title="老板生日" >
				<u-input inputAlign="right" placeholder="老板生日" :value="birthday" @click="showBirthdayPicker = true" type="select" :arrow="false" :selectOpen="showBirthdayPicker"></u-input>
			</u-cell-item>
			<u-cell-item :arrow="false" style="padding: 0 30rpx 0 0;">
				<text class="u-font-10">*此生日为公历(阳历)生日，请填写正确的生日日期，以免短信发送错误</text>
			</u-cell-item>
		</block>
		
		<u-cell-item v-if="showIsVip && (selectedFields.includes(29) || displayAll) " :arrow="false" title="是否VIP">
			<u-radio-group v-model="form.IsVIP">
				<u-radio :name="1">是</u-radio>
				<u-radio :name="0">否</u-radio>
			</u-radio-group>
		</u-cell-item>
		<u-cell-item v-if="selectedFields.includes(30) ||displayAll" :arrow="false" title="祝福备注">
			<u-input placeholder="祝福备注" v-model="form.BlessingNote" :customStyle="{ fontSize: '26rpx', color: '#909399'}" type="textarea" inputAlign="right"></u-input>
		</u-cell-item>
		
		<u-picker :default-time="form.BossBirthday ? $u.date(form.BossBirthday * 1000, 'yyyy-mm-dd') : $u.date(new Date(), 'yyyy-mm-dd')" @confirm="onBirthdayChange" v-model="showBirthdayPicker" mode="time" :params="{year: true, month: true, day: true}"></u-picker>
	</u-cell-group>
</template>

<script>
export default {
	name: 'boss-information-form',
	props: {
		level: {
			type: [Number, String],
			default: 1
		},
		showIsVip: {
			type: Boolean,
			default: false
		},
		selectedFields: {
			type: Array,
			default() {
				return []
			}
		},
		displayAll: {
			type: Boolean,
			default: true
		},
	},
	data() {
		return {
			showBirthdayPicker: false,
			form: {
				BossName: '',
				BossPhone: '',
				BossBirthday: null,
				IsVIP: null,
				BlessingNote: ''
			}
		};
	},
	
	computed: {
		birthday() {
			if(this.form.BossBirthday) {
				return this.$u.date(this.form.BossBirthday * 1000)
			}else {
				return ''
			}
		}
	},

	methods: {
		initForm(data) {
			if(data) {
				this.form = Object.assign(this.form, data);
			}
		},
		
		onBirthdayChange(e) {
			this.form.BossBirthday = parseInt(new Date(`${e.year}-${e.month}-${e.day}`).getTime() / 1000)
		},
		
		addPrefix(text) {
			let prefix = '';
			if (this.level == 1) {
				prefix = '一级';
			}
			if (this.level == 2) {
				prefix = '二级';
			}
			return prefix + text;
		}
	}
};
</script>

<style lang="scss"></style>
